/*
 * Copyright (c) 2018. paascloud.net All Rights Reserved.
 * 项目名称：paascloud快速搭建企业级分布式微服务平台
 * 类名称：AliyunSmsConstants.java
 * 创建人：刘兆明
 * 联系方式：paascloud.net@gmail.com
 * 开源地址: https://github.com/paascloud
 * 博客地址: http://blog.paascloud.net
 * 项目官网: http://paascloud.net
 */
package com.csun.cmny.base.constant;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.base.exception.BusinessException;
import com.google.common.collect.Lists;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * The class Aliyun sms constants.
 *
 * @author paascloud.net@gmail.com
 */
public class AliyunSmsConstants {

	/**
	 * aliyun sms app key
	 */
	public static final String SMS_KEY = "FZR1MOSb8cy3xhNo";

	public static final String SMS_SECRET = "Ib3dZdcoLHpkYhwsLIsO8QblVogg6P";

	/**
	 * 短信模板枚举
	 */
	public enum SmsTemplateEnum {

		/**
		 * 通用模板(短信内容:验证码${code}, 您正在注册成为paasCloud用户, 感谢您的支持！)
		 */
		// UAC_PC_GLOBAL_TEMPLATE("UAC_PC_GLOBAL_TEMPLATE", "SMS_7776133", "code"),
		//
		/**
		 * 登录确认验证码模板. (验证码${code}，您正在登录${product}，若非本人操作，请勿泄露。)
		 */
		DEFAULT_CHECK_AUTH_CODE("DEFAULT_CHECK_AUTH_CODE", "SMS_174991155", "code"),
		/**
		 * 登录确认验证码模板. (验证码${code}，您正在登录${product}，若非本人操作，请勿泄露。)
		 */
		PHONE_LOGIN_AUTH_CODE("PHONE_LOGIN_AUTH_CODE", "SMS_7776135", "code"),
		/**
		 * 用户注册验证码模板. (验证码${code}，您正在注册成为${product}用户，感谢您的支持！)
		 */
		REGISTER_USER_AUTH_CODE("REGISTER_USER_AUTH_CODE", "SMS_7776133", "code"),
		/**
		 * 修改密码验证码模板. (验证码${code}，您正在尝试修改${product}登录密码，请妥善保管账户信息。)
		 */
		MODIFY_PASSWORD_AUTH_CODE("MODIFY_PASSWORD_AUTH_CODE", "SMS_7776131", "code");

		private String busType;

		private String templateCode;

		private String smsParamName;

		public static SmsTemplateEnum getBusType(String busType) {
			SmsTemplateEnum smsTemplateEnum = null;
			for (SmsTemplateEnum ele : SmsTemplateEnum.values()) {
				if (busType.equals(ele.getBusType())) {
					smsTemplateEnum = ele;
					break;
				}
			}
			return smsTemplateEnum;
		}

		public static SmsTemplateEnum getEnum(String templateCode) {
			SmsTemplateEnum smsTemplateEnum = null;
			for (SmsTemplateEnum ele : SmsTemplateEnum.values()) {
				if (templateCode.equals(ele.getTemplateCode())) {
					smsTemplateEnum = ele;
					break;
				}
			}
			return smsTemplateEnum;
		}

		public static boolean isSmsTemplate(String smsTemplateCode) {

			if (StringUtils.isEmpty(smsTemplateCode)) {
				throw new BusinessException(ErrorCodeEnum.UAC10011020);
			}
			List<String> templetCodeList = getTemplateCodeList();

			return templetCodeList.contains(smsTemplateCode);
		}

		public static List<SmsTemplateEnum> getList() {
			return Arrays.asList(SmsTemplateEnum.values());
		}

		public static List<String> getTemplateCodeList() {
			List<String> templateCodeList = Lists.newArrayList();
			List<SmsTemplateEnum> list = getList();
			for (SmsTemplateEnum templateEnum : list) {
				if (StringUtils.isEmpty(templateEnum.getTemplateCode())) {
					continue;
				}
				templateCodeList.add(templateEnum.getTemplateCode());
			}
			return templateCodeList;
		}

		SmsTemplateEnum(String busType, String templateCode, String smsParamName) {
			this.busType = busType;
			this.templateCode = templateCode;
			this.smsParamName = smsParamName;
		}

		/**
		 * Gets bus type.
		 *
		 * @return the bus type
		 */
		public String getBusType() {
			return busType;
		}

		/**
		 * Gets templet code.
		 *
		 * @return the template code
		 */
		public String getTemplateCode() {
			return templateCode;
		}

		/**
		 * Gets sms param name.
		 *
		 * @return the sms param name
		 */
		public String getSmsParamName() {
			return smsParamName;
		}
	}


}
